﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Gmis.IDAL;
using Gmis.DBUtility;

namespace Gmis.SqlServerDAL
{
    /// <summary>
    /// 数据访问类:ArtelMember
    /// </summary>
    public partial class ArtelMember : IArtelMember
    {
        public ArtelMember()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ArtelMember");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.ArtelMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ArtelMember(");
            strSql.Append("sId,sArtelId,sWorkUnit,sName,dJoin,sPosition,sScale,sType,nArea,sAddress,sMobile,sComment)");
            strSql.Append(" values (");
            strSql.Append("@sId,@sArtelId,@sWorkUnit,@sName,@dJoin,@sPosition,@sScale,@sType,@nArea,@sAddress,@sMobile,@sComment)");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50),
					new SqlParameter("@sArtelId", SqlDbType.VarChar,50),
					new SqlParameter("@sWorkUnit", SqlDbType.NVarChar,128),
					new SqlParameter("@sName", SqlDbType.NVarChar,50),
					new SqlParameter("@dJoin", SqlDbType.DateTime),
					new SqlParameter("@sPosition", SqlDbType.NVarChar,50),
					new SqlParameter("@sScale", SqlDbType.NVarChar,50),
					new SqlParameter("@sType", SqlDbType.NVarChar,50),
					new SqlParameter("@nArea", SqlDbType.Decimal,9),
					new SqlParameter("@sAddress", SqlDbType.NVarChar,128),
					new SqlParameter("@sMobile", SqlDbType.NVarChar,50),
					new SqlParameter("@sComment", SqlDbType.NVarChar,300)};
            parameters[0].Value = model.sId;
            parameters[1].Value = model.sArtelId;
            parameters[2].Value = model.sWorkUnit;
            parameters[3].Value = model.sName;
            parameters[4].Value = model.dJoin;
            parameters[5].Value = model.sPosition;
            parameters[6].Value = model.sScale;
            parameters[7].Value = model.sType;
            parameters[8].Value = model.nArea;
            parameters[9].Value = model.sAddress;
            parameters[10].Value = model.sMobile;
            parameters[11].Value = model.sComment;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.ArtelMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ArtelMember set ");
            strSql.Append("sArtelId=@sArtelId,");
            strSql.Append("sWorkUnit=@sWorkUnit,");
            strSql.Append("sName=@sName,");
            strSql.Append("dJoin=@dJoin,");
            strSql.Append("sPosition=@sPosition,");
            strSql.Append("sScale=@sScale,");
            strSql.Append("sType=@sType,");
            strSql.Append("nArea=@nArea,");
            strSql.Append("sAddress=@sAddress,");
            strSql.Append("sMobile=@sMobile,");
            strSql.Append("sComment=@sComment");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sArtelId", SqlDbType.VarChar,50),
					new SqlParameter("@sWorkUnit", SqlDbType.NVarChar,128),
					new SqlParameter("@sName", SqlDbType.NVarChar,50),
					new SqlParameter("@dJoin", SqlDbType.DateTime),
					new SqlParameter("@sPosition", SqlDbType.NVarChar,50),
					new SqlParameter("@sScale", SqlDbType.NVarChar,50),
					new SqlParameter("@sType", SqlDbType.NVarChar,50),
					new SqlParameter("@nArea", SqlDbType.Decimal,9),
					new SqlParameter("@sAddress", SqlDbType.NVarChar,128),
					new SqlParameter("@sMobile", SqlDbType.NVarChar,50),
					new SqlParameter("@sComment", SqlDbType.NVarChar,300),
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = model.sArtelId;
            parameters[1].Value = model.sWorkUnit;
            parameters[2].Value = model.sName;
            parameters[3].Value = model.dJoin;
            parameters[4].Value = model.sPosition;
            parameters[5].Value = model.sScale;
            parameters[6].Value = model.sType;
            parameters[7].Value = model.nArea;
            parameters[8].Value = model.sAddress;
            parameters[9].Value = model.sMobile;
            parameters[10].Value = model.sComment;
            parameters[11].Value = model.sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ArtelMember ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string sIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ArtelMember ");
            strSql.Append(" where sId in (" + sIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.ArtelMember GetModel(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 sId,sArtelId,sWorkUnit,sName,dJoin,sPosition,sScale,sType,nArea,sAddress,sMobile,sComment from ArtelMember ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            Gmis.Model.ArtelMember model = new Gmis.Model.ArtelMember();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["sId"] != null && ds.Tables[0].Rows[0]["sId"].ToString() != "")
                {
                    model.sId = ds.Tables[0].Rows[0]["sId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sArtelId"] != null && ds.Tables[0].Rows[0]["sArtelId"].ToString() != "")
                {
                    model.sArtelId = ds.Tables[0].Rows[0]["sArtelId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sWorkUnit"] != null && ds.Tables[0].Rows[0]["sWorkUnit"].ToString() != "")
                {
                    model.sWorkUnit = ds.Tables[0].Rows[0]["sWorkUnit"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sName"] != null && ds.Tables[0].Rows[0]["sName"].ToString() != "")
                {
                    model.sName = ds.Tables[0].Rows[0]["sName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dJoin"] != null && ds.Tables[0].Rows[0]["dJoin"].ToString() != "")
                {
                    model.dJoin = DateTime.Parse(ds.Tables[0].Rows[0]["dJoin"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sPosition"] != null && ds.Tables[0].Rows[0]["sPosition"].ToString() != "")
                {
                    model.sPosition = ds.Tables[0].Rows[0]["sPosition"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sScale"] != null && ds.Tables[0].Rows[0]["sScale"].ToString() != "")
                {
                    model.sScale = ds.Tables[0].Rows[0]["sScale"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sType"] != null && ds.Tables[0].Rows[0]["sType"].ToString() != "")
                {
                    model.sType = ds.Tables[0].Rows[0]["sType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["nArea"] != null && ds.Tables[0].Rows[0]["nArea"].ToString() != "")
                {
                    model.nArea = decimal.Parse(ds.Tables[0].Rows[0]["nArea"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sAddress"] != null && ds.Tables[0].Rows[0]["sAddress"].ToString() != "")
                {
                    model.sAddress = ds.Tables[0].Rows[0]["sAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sMobile"] != null && ds.Tables[0].Rows[0]["sMobile"].ToString() != "")
                {
                    model.sMobile = ds.Tables[0].Rows[0]["sMobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sComment"] != null && ds.Tables[0].Rows[0]["sComment"].ToString() != "")
                {
                    model.sComment = ds.Tables[0].Rows[0]["sComment"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sId,sArtelId,sWorkUnit,sName,dJoin,sPosition,sScale,sType,nArea,sAddress,sMobile,sComment ");
            strSql.Append(" FROM ArtelMember ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" sId,sArtelId,sWorkUnit,sName,dJoin,sPosition,sScale,sType,nArea,sAddress,sMobile,sComment ");
            strSql.Append(" FROM ArtelMember ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "ArtelMember";
            parameters[1].Value = "sId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

